#include "touch.h"


int x,y;

int touch_wait()
{
	//1、打开触摸屏设备文件 /dev/input/event0
	int tsFd = open("/dev/input/event0",O_RDWR);
	if(tsFd == -1)
	{
		perror("open ts error");
		return -1;
	}
	//2、读取触摸屏数据 --坐标
	while(1)
	{
		struct input_event info;
		read(tsFd,&info,sizeof(struct input_event));
		
		//判断是触摸屏事件&&X轴事件
		if(info.type == 3 && info.code == 0)
		{
			x = info.value;
		}
		//判断是触摸屏事件&&Y轴事件
		if(info.type == 3 && info.code == 1)
		{
			y = info.value;
		}
		//按下
		/* if(info.type == 1 && info.code == 330 && info.value==1)
		{
			printf("手按下(%d,%d)\n",x,y);
		} */
		//松开 
		if(info.type == 1 && info.code == 330 && info.value==0)
		{
			//如果是边框是黑色板子的同学，需要进行坐标更新
			x = x * 800 *1.0/ 1024;
			y = y * 480 *1.0/ 600;
			printf("手松开 (%d,%d)\n",x,y);
			break;
		}
		//3、打印坐标
		//printf("type:%d code:%d value:%d\n",info.type,info.code,info.value);
	
	}
	
	//4、关闭触摸屏文件
	close(tsFd);
	
}
